#coding:utf8
from django import template
from django.utils.html import format_html
register = template.Library()

#配置分页
# @register.simple_tag()
def guess_page(current_page, loop_num):
    offset = abs(current_page - loop_num)

    if offset < 2:
        if current_page == loop_num:
            page_element = '''
             <li class="active">
                <a href="?page={loop_num}">{loop_num}<span class="sr-only">(current)</span></a>
             </li>'''.format(loop_num=loop_num)
        else:
            page_element = '''
            <li>
                <a href="?page={loop_num}">{loop_num}<span class="sr-only">(current)</span></a>
            </li>'''.format(loop_num=loop_num)
        return format_html(page_element)
    else:
        return ''


